package com.ehaoyao.utils;

import java.io.*;

/**
 * @program: demo
 * @description: FileUtils
 * @author: zhangyp
 * @create: 2020-08-04
 */
public class FileUtils2 {

    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\Administrator\\Desktop\\fat.txt");
        File file1 = new File("C:\\Users\\Administrator\\Desktop\\fat1.txt");
        StringBuilder result = new StringBuilder();
        BufferedReader br = null;
        try{
            br = new BufferedReader(new FileReader(file));
            String s = new String();
            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                result.append(s.replace(",","\\r\\n"));
            }
        }catch (Exception e){
        }finally {
            if(br != null){
                br.close();
            }
        }
        System.out.println(result.toString());
        file1.createNewFile();
        BufferedWriter out = new BufferedWriter(new FileWriter(file1));
        out.write(result.toString()); // \r\n即为换行
        out.flush(); // 把缓存区内容压入文件
        out.close(); // 最后记得关闭文件
    }
}